/**
 * @file        edb_base_plug.c
 * @brief       win平台基础插件功能
 * @note        1.与其他进程通讯,实现数据的读写
 *              2.属性掉电存储
 * @author      靳普诏(puzhao.jin@hopechart.com)
 * @date        2025/03/29
 * @version     1.0

 * @par         修改日志
 * <table>
 * <tr><th>Date         <th>Version     <th>Author      <th> Description
 * <tr><td>2025/03/29   <td>1.0         <td>靳普诏       <td> 创建初始版本
 * @copyright 杭州鸿泉物联网技术股份有限公司
 */
 
#include "edb_base_plug.h"
#include <windows.h>
#include <process.h>
#include <stdio.h>
#include "sfc/sfc_thread.h"

// 线程函数
TSfThread g_edb_ipc_thread = {0};


// 线程函数
static Int32 EdbBasePlugIpcThread(TSfThread *self)
{
    static int i = 0;

    printf("EdbBasePlugIpcThread i:%d\n", i++);
    return 20;
}

void EdbBasePlugInit(TEdb *sender, void *user_param)
{
    // 创建线程用于监听其他进程的消息
    const TSfThreadAttr attr = {
        .name = "edb_ipc_thread",
        .priority = kSfThreadPriorityNormal,
        .stack = NULL,
        .stack_size = 0,
    };

    Bool ret = TSfThreadCreateEx(&g_edb_ipc_thread, &attr);

    if (ret) 
    {
        g_edb_ipc_thread.OnRunOnce = EdbBasePlugIpcThread;
    }

}

void EdbBasePlugOpen(TEdb *sender, void *user_param)
{
    TSfThreadResume(&g_edb_ipc_thread);
}

void EdbBasePlugRunOnce(TEdb *sender, void *user_param)
{

}

void EdbBasePlugClose(TEdb *sender, void *user_param)
{
    TSfThreadTerminate(&g_edb_ipc_thread);
    TSfThreadWaitFor(&g_edb_ipc_thread, -1);
}

void EdbBasePlugDone(TEdb *sender, void *user_param)
{
    TSfThreadDestroy(&g_edb_ipc_thread);
}

void EdbBasePlugOnValueChange(TEdb *sender, void *user_param, UInt16 did)
{

}





